﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <div>
    <el-form ref="formRefMachine" :model="stateMachine.vmModel" label-width="100px">
      <el-row>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_LineCodeId_FormItem" prop="Entity.LineCodeId" :label="$t('message.autotrans._Model_Machine_LineCode')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_Machine_LineCode')}), trigger: 'blur' }]" >
            <el-select v-model="stateMachine.vmModel.Entity.LineCodeId" disabled clearable>
               <el-option v-for="item in stateMachine.AllLineCodes" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_StationCodeId_FormItem" prop="Entity.StationCodeId" :label="$t('message.autotrans._Model_Machine_StationCode')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_Machine_StationCode')}), trigger: 'blur' }]" >
            <el-select v-model="stateMachine.vmModel.Entity.StationCodeId" disabled clearable>
               <el-option v-for="item in stateMachine.AllStationCodes" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_MachineCode_FormItem" prop="Entity.MachineCode" :label="$t('message.autotrans._Model_Machine_MachineCode')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_Machine_MachineCode')}), trigger: 'blur' }]" >
            <el-input v-model="stateMachine.vmModel.Entity.MachineCode" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_MachineName_FormItem" prop="Entity.MachineName" :label="$t('message.autotrans._Model_Machine_MachineName')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_Machine_MachineName')}), trigger: 'blur' }]" >
            <el-input v-model="stateMachine.vmModel.Entity.MachineName" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Asset_FormItem" prop="Entity.Asset" :label="$t('message.autotrans._Model_Machine_Asset')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_Machine_Asset')}), trigger: 'blur' }]" >
            <el-input v-model="stateMachine.vmModel.Entity.Asset" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_RatedPower_FormItem" prop="Entity.RatedPower" :label="$t('message.autotrans._Model_Machine_RatedPower')">
            <el-input v-model="stateMachine.vmModel.Entity.RatedPower" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_PersonCode_FormItem" prop="Entity.PersonCode" :label="$t('message.autotrans._Model_Machine_PersonCode')">
            <el-input v-model="stateMachine.vmModel.Entity.PersonCode" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_MachineStatus_FormItem" prop="Entity.MachineStatus" :label="$t('message.autotrans._Model_Machine_MachineStatus')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_Machine_MachineStatus')}), trigger: 'blur' }]" >
            <el-select v-model="stateMachine.vmModel.Entity.MachineStatus" disabled clearable>
               <el-option key="NORMAL" value="NORMAL" :label="$t('message.autotrans._Enum_EquipmentStatus_NORMAL')"></el-option>
               <el-option key="FREE" value="FREE" :label="$t('message.autotrans._Enum_EquipmentStatus_FREE')"></el-option>
               <el-option key="MAINTAIN" value="MAINTAIN" :label="$t('message.autotrans._Enum_EquipmentStatus_MAINTAIN')"></el-option>
               <el-option key="OFFLINE" value="OFFLINE" :label="$t('message.autotrans._Enum_EquipmentStatus_OFFLINE')"></el-option>
               <el-option key="REPAIR" value="REPAIR" :label="$t('message.autotrans._Enum_EquipmentStatus_REPAIR')"></el-option>
               <el-option key="SCRAP" value="SCRAP" :label="$t('message.autotrans._Enum_EquipmentStatus_SCRAP')"></el-option>
               <el-option key="ON_MACHINE" value="ON_MACHINE" :label="$t('message.autotrans._Enum_EquipmentStatus_ON_MACHINE')"></el-option>
               <el-option key="IN_LIBRARY" value="IN_LIBRARY" :label="$t('message.autotrans._Enum_EquipmentStatus_IN_LIBRARY')"></el-option>
               <el-option key="IN_MAINTAIN" value="IN_MAINTAIN" :label="$t('message.autotrans._Enum_EquipmentStatus_IN_MAINTAIN')"></el-option>
               <el-option key="OVERHAUL" value="OVERHAUL" :label="$t('message.autotrans._Enum_EquipmentStatus_OVERHAUL')"></el-option>
               <el-option key="CH_M_AND_T" value="CH_M_AND_T" :label="$t('message.autotrans._Enum_EquipmentStatus_CH_M_AND_T')"></el-option>
               <el-option key="FAULT" value="FAULT" :label="$t('message.autotrans._Enum_EquipmentStatus_FAULT')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_CreateTime_FormItem" prop="Entity.CreateTime" :label="$t('message.autotrans._Model_Machine_CreateTime')">
            <el-input v-model="stateMachine.vmModel.Entity.CreateTime" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_UpdateTime_FormItem" prop="Entity.UpdateTime" :label="$t('message.autotrans._Model_Machine_UpdateTime')">
            <el-input v-model="stateMachine.vmModel.Entity.UpdateTime" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_CreateBy_FormItem" prop="Entity.CreateBy" :label="$t('message.autotrans._Model_Machine_CreateBy')">
            <el-input v-model="stateMachine.vmModel.Entity.CreateBy" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_UpdateBy_FormItem" prop="Entity.UpdateBy" :label="$t('message.autotrans._Model_Machine_UpdateBy')">
            <el-input v-model="stateMachine.vmModel.Entity.UpdateBy" disabled clearable></el-input>
        </el-form-item>

        </el-col>
      </el-row>

      <div style="text-align:right;">
        <WtmButton @click="onCloseMachine"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

      </div>

    </el-form>

  </div>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageBaseInformationMachineDetails;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { machineApi } from '/@/api/baseinformation/machine';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const formRefMachine = ref();
const stateMachine = reactive({
    vmModel: {
	  Entity:{
        LineCodeId: null,
        StationCodeId: null,
        MachineCode: '',
        MachineName: '',
        Asset: '',
        RatedPower: null,
        PersonCode: '',
        MachineStatus: undefined,
        CreateTime: undefined,
        UpdateTime: undefined,
        CreateBy: '',
        UpdateBy: '',
        ID:null,
      },

	},
    
    AllLineCodes: [] as any[],
    AllStationCodes: [] as any[],
});

// 取消
const onCloseMachine = () => {
    closeDialog();
};

// 提交
const onSubmitMachine = () => {
 	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});
   formRefMachine.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            machineApi().edit(stateMachine.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
	})
};

// 页面加载时
onMounted(() => {
    
    other.getSelectList('/api/BaseInformation/Machine/GetLines',[],false).then(x=>{stateMachine.AllLineCodes = x});
    other.getSelectList('/api/BaseInformation/Machine/GetStations',[],false).then(x=>{stateMachine.AllStationCodes = x});
    if (ci.attrs["wtmdata"]) {
		stateMachine.vmModel.Entity.ID = ci.attrs["wtmdata"].ID;
	}
	else if (useRouter().currentRoute.value.query.id) {
		stateMachine.vmModel.Entity.ID = useRouter().currentRoute.value.query.id as any;
	}
	machineApi().get(stateMachine.vmModel.Entity.ID ?? "").then((data: any) => other.setValue(stateMachine.vmModel, data));
});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

